<?php


namespace App\Repositories;

//真心话大冒险
use App\Exceptions\BasicException;

class TruthDareRepository
{
    public function addOrEdit($param)
    {
        $id = $param['id'] ?? 0;
        $titleName = $param['title_name'];
        $titleType = $param['title_type'];
        $status = $param['status'];

        $data = [
            'title' => $titleName,
            'type' => $titleType,
            'status' => $status,
        ];
        if ($id > 0) {
            $truthDareId = app('model_truth_dare')->where('id', $id)->value('id');
            if (empty($truthDareId)) throw new BasicException(0, 'id错误，记录不存在');

            $res = app('model_truth_dare')->where('id', $id)->update($data);
        } else {
            $res = app('model_truth_dare')->insert($data);
        }
        return $res;
    }
}